//
//  TMGLastEepectTableViewCell.m
//  TMGold
//
//  Created by Mac on 2018/3/29.
//  Copyright © 2018年 tangmu. All rights reserved.
//

#import "TMGLastEepectTableViewCell.h"
#import "NSCalendar+STCalendarTool.h"
@interface  TMGLastEepectTableViewCell()
@property(nonatomic, strong) STLabel                     *nameLable;
@property(nonatomic, strong) STLabel                     *statusLable;
@property(nonatomic, strong) STLabel                     *sendlable;//发送时间
@property(nonatomic, strong) STLabel                     *beginlable;//计息开始时间
@property(nonatomic, strong) STLabel                     *endlable;//计息结束时间
@property(nonatomic, strong) STLabel                     *rateLable;
@end
@implementation TMGLastEepectTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeigh{
    return 120;
}
#pragma mark --subView
- (void)configSubView{
    self.nameLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 10, 200, 30)
                                                     text:@""
                                                textColor:FirstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.nameLable];
    
    
    self.statusLable = [[STLabel alloc] initWithFrame:CGRectMake(self.nameLable.right + 5, 10, 45, 30)
                                               text:@"计息中"
                                          textColor:[UIColor whiteColor]
                                               font:12
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentCenter];
    self.statusLable.centerY = self.nameLable.centerY;
    self.statusLable.backgroundColor = [UIColor colorWithRed:214/255.0 green:214/255.0 blue:214/255.0 alpha:1];
    self.statusLable.layer.cornerRadius = 0;
    self.statusLable.clipsToBounds = YES;
    [self addSubview:self.statusLable];
    
    
    self.rateLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 10, 200, 30)
                                               text:@""
                                          textColor:TM_orangeColor
                                               font:18
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentRight];
    self.rateLable.right = UIScreenWidth - 10;
    [self addSubview:self.rateLable];
    
    
    self.sendlable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.nameLable.bottom, 200, 20)
                                               text:@""
                                          textColor:SecendTextColor
                                               font:12
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.sendlable];
    
   STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(10, self.nameLable.bottom, 200, 20)
                                               text:@"最终黄金收益率"
                                          textColor:SecendTextColor
                                               font:12
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentRight];
    desLable.right = UIScreenWidth - 10;
    [self addSubview:desLable];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(10, self.sendlable.bottom + 10, UIScreenWidth - 20, 0.5)];
    line.backgroundColor = TM_lineColor;
    [self addSubview:line];
    
    
    self.beginlable = [[STLabel alloc] initWithFrame:CGRectMake(10, line.bottom, UIScreenWidth/2, 44)
                                               text:@""
                                          textColor:SecendTextColor
                                               font:12
                                        isSizetoFit:NO
                                      textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.beginlable];
    [self.beginlable st_showRightLine:20];
    
    
    self.endlable = [[STLabel alloc] initWithFrame:CGRectMake(10, line.bottom, UIScreenWidth/2, 44)
                                                text:@""
                                           textColor:SecendTextColor
                                                font:12
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentRight];
    self.endlable.right = UIScreenWidth - 10;
    [self addSubview:self.endlable];

}
- (void)setModel:(TMGLastExpectModel *)model{
    _model = model;
    self.nameLable.text = model.name;
    NSString * rate = model.year_rate_from;
    if (model.year_rate_to.floatValue > 0.1) {
        rate = [NSString stringWithFormat:@"%@~%@",model.year_rate_from,model.year_rate_to];
    }
    NSString * modelRate = [NSString stringWithFormat:@"%@%%",rate];
    
    
    self.rateLable.text = modelRate;
    [NSString lableAutoAdjustWitdhWithLabel:self.nameLable];
    self.statusLable.left = self.nameLable.right + 10;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSTimeZone* GTMzone = [NSTimeZone timeZoneForSecondsFromGMT:0];
    [formatter setTimeZone:GTMzone];
    NSDate * dealdLineDate = [formatter dateFromString:model.deadline];
    
    NSDate * date = [dealdLineDate.st_localDate copy];
    
    NSDate * tormmorDate = [NSCalendar st_nextDayDate:date];
    
    NSDate * endDate = [tormmorDate copy];
    for (NSInteger i = 0; i < model.day_number.integerValue; i ++) {
        endDate = [NSCalendar st_nextDayDate:endDate];
    }
    NSDate * shouyiDate = [NSCalendar st_nextDayDate:endDate];
    
    self.sendlable.text = [NSString stringWithFormat:@"本息发放日:%@",shouyiDate.st_yyyyMMddByLineWithDate];
    
    self.beginlable.text = [NSString stringWithFormat:@"计息开始日:%@",tormmorDate.st_yyyyMMddByLineWithDate];
    
    self.endlable.text = [NSString stringWithFormat:@"计息结束日:%@",endDate.st_yyyyMMddByLineWithDate];
}
@end
